*************************************************************************************
*************************************************************************************
** Replication code for:
** US Public Perceptions of an Intelligence Quotient Test Score Gap Between Black Americans and White Americans 
** GSS 2012
** dataset downloaded 7 Jan 2019
** http://gss.norc.org/get-the-data/stata
** Stata 15
*************************************************************************************
*************************************************************************************

set more off
svyset vpsu [pw=wtssall], strata(vstrat) singleunit(centered)

*******************************************************************************************************************************
*** Stereotype: intelligent
*******************************************************************************************************************************

tab1 intlwhts intlblks      
tab1 intlwhts intlblks, mi
tab1 intlwhts intlblks, nol mi
di 1974-672 // N=1302 who could have rated W>B

gen intelWB = 0
replace intelWB = 1 if intlwhts>intlblks
replace intelWB = . if intlwhts==.i | intlblks==.i 
replace intelWB = 0 if intlwhts==.d | intlblks==.d | intlwhts==.n | intlblks==.n
tab intelWB // N=1302 who could have rated W>B

tab intlwhts intlblks if intelWB==1, mi
tab intlwhts intlblks if intelWB==0, mi
tab intlwhts intlblks if intelWB==., mi
sum intelWB

*******************************************************************************************************************************
*** Racial groups
*******************************************************************************************************************************

tab hispanic race, mi
gen whiteNH = 0
gen blackNH = 0
replace whiteNH=1 if race==1 & hispanic==1
replace blackNH=1 if race==2 & hispanic==1
tab race hispanic if whiteNH==1, mi
tab race hispanic if blackNH==1, mi

* Compare to NH White moderate % in YouGov data
tab polviews, mi
tab polviews, nol mi
gen pol8 = polviews
replace pol8=8 if polviews==.d | polviews==.n // recode so that 8 is don't know or no answer
tab pol8 polviews, mi
svy: tab pol8 if whiteNH==1
di 0.0303 + 0.1153 + 0.1069 // liberal
di 0.0332 + 0.1731 + 0.1598 // conservative
di 0.3419                   // moderate
di 0.0395                   // don't know or no answer

tab polviews
tab polviews, nol mi
gen liberal=0
gen conserv=0
replace liberal=1 if polviews==1 | polviews==2 | polviews==3
replace conserv=1 if polviews==5 | polviews==6 | polviews==7
tab polviews liberal, mi
tab polviews conserv, mi

gen whiteNHlib = 0
gen whiteNHcon = 0
replace whiteNHlib=1 if whiteNH==1 & liberal==1
replace whiteNHcon=1 if whiteNH==1 & conserv==1
tab polviews whiteNHlib, mi
tab polviews whiteNHcon, mi
tab race whiteNHlib, mi
tab race whiteNHcon, mi
tab hispanic whiteNHlib, mi
tab hispanic whiteNHcon, mi

*******************************************************************************************************************************
*** Analyses
*******************************************************************************************************************************

svyset vpsu [pw=wtssall], strata(vstrat) singleunit(centered)
svy:                     prop intelWB, level(84)
svy, subpop(whiteNH):    prop intelWB, level(84)
svy, subpop(blackNH):    prop intelWB, level(84)
svy, subpop(whiteNHlib): prop intelWB, level(84)
svy, subpop(whiteNHcon): prop intelWB, level(84)
